<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    ul, li {
      list-style: none;
    }

    ul {
      width: 1200px;
      display: flex;
      flex-wrap: wrap;
      margin: 0 auto;
      justify-content: space-between;
      padding-top: 10px;
    }

    li {
      width: 290px;
      border: 1px solid #333;
      margin-bottom: 10px;
      padding: 5px;
      box-sizing: border-box;
    }

    li > img {
      width: 278px;
      display: block;
    }
    header {
      height: 200px;
      background-color: cadetblue;
      text-align: center;
      line-height: 200px;
      font-size: 50px;
    }
    .tips {
      width: 400px;
      height: 50px;
      background-color: rgba(0, 0, 0, 0.1);
      font-size: 32px;
      text-align: center;
      line-height: 50px;
      position: fixed;
      bottom: 0;
      left: 50%;
      transform: translateX(-50%);
      display: none;
    }
  </style>
</head>
<body>
  <header>顶部内容</header>
  <ul>
  
    <!-- 
    <li>
      <img src="https://img.alicdn.com/bao/uploaded/https://img.alicdn.com/imgextra/i3/2251059038/O1CN01zJEpaN2GdSG1Xvo8y_!!2251059038.jpg" alt="">
      <p>音乐节名称</p>
      <p>城市: xx</p>
      <p>地址: xx</p>
      <p>价格: xx</p>
      <p>时间: xx</p>
    </li>  
  -->

  </ul>

  <div class="tips">数据加载完毕</div>
</body>
</html>
<script src="./dm_list.js"></script>

<script>
const domUl = document.querySelector('ul');
const domTips = document.querySelector('.tips');

const pageSize = 8; // 表示 每页的 个数
const total = Math.ceil(list.length / pageSize); // 一共有的 页数

let currentPage = 1; // 表示当前页数

const render = () => {
  if (currentPage > total) {
    domTips.style.display = 'block';
    // 只要执行 return ，其下面的代码都不会被执行
    return;
  }

  // 第一页数据：list.slice(0, 8)
  // 第二页数据：list.slice(8, 16)
  // 第N页： list.slice((currentPage - 1) * 8, currentPage * 8)

  const renderData = list.slice((currentPage - 1) * 8, currentPage * 8);

  domUl.innerHTML += renderData.map(d => `
    <li>
      <img src="${d.pic}" alt="">
      <p>${d.name}</p>
      <p>城市: ${d.city}</p>
      <p>地址: ${d.address}</p>
      <p>价格: ${d.price}</p>
      <p>时间: ${d.showTime}</p>
    </li>
  `).join('');

  currentPage++;
}

render();

window.onscroll = function() {
  // const bottom =  domUl.getBoundingClientRect().bottom;
  // 用 对象的 解构赋值 改写上面的代码
  const { bottom, x, y } = domUl.getBoundingClientRect();

  console.log(bottom, x, y, domUl.getBoundingClientRect());
  if (bottom <= window.innerHeight) {
    render();
    console.log('scroll - 到底拉！！！', );
  }
}
</script>